home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / magicheaven.swf / scripts / __Packages / key_func.as
Text File  |  2007-10-01  |  3KB  |  109 lines

  1. class key_func extends MovieClip
  2. {
  3.    function key_func(arr, OBJ, OBJ2, tmp, func_, time)
  4.    {
  5.       function funcForObj()
  6.       {
  7.          if(OBJ.num > 1)
  8.          {
  9.             if(arguments[2] - arguments[1] > time || arguments[2] - arguments[1] < 0)
  10.             {
  11.                OBJ2.blo = true;
  12.                OBJ.num = 1;
  13.                OBJ2.what = 0;
  14.             }
  15.             else if(arguments[2] - arguments[1] <= time)
  16.             {
  17.                if(Key.getCode() == arr[OBJ2.what + 1])
  18.                {
  19.                   OBJ2.what = OBJ2.what + 1;
  20.                }
  21.                if(OBJ2.what == arr.length - 1)
  22.                {
  23.                   func_(this.prop,this.oldVal,this.newVal,this.mid_val);
  24.                   OBJ.num = 0;
  25.                   OBJ2.what = 0;
  26.                }
  27.             }
  28.          }
  29.       }
  30.       super();
  31.       var OBJ = new Object();
  32.       var OBJ2 = new Object();
  33.       OBJ2.key;
  34.       OBJ2.what = 0;
  35.       OBJ.num = 0;
  36.       OBJ.num2 = 0;
  37.       OBJ.onKeyDown = function()
  38.       {
  39.          if(this.once == undefined)
  40.          {
  41.             this.once = 1;
  42.             if(OBJ2.blo == undefined)
  43.             {
  44.                if(Key.getCode() == arr[this.num])
  45.                {
  46.                   this.num = this.num + 1;
  47.                }
  48.             }
  49.             else if(Key.getCode() == arr[this.num] && OBJ2.blo !== undefined)
  50.             {
  51.                this.num = this.num + 1;
  52.             }
  53.             else if(Key.getCode() != arr[this.num])
  54.             {
  55.                this.num = 0;
  56.                delete OBJ2.blo;
  57.             }
  58.             OBJ2.key = getTimer();
  59.             if(this.num > arr.length)
  60.             {
  61.                this.num = 0;
  62.             }
  63.          }
  64.       };
  65.       var cnt = 0;
  66.       tmp.onEnterFrame = function()
  67.       {
  68.          cnt++;
  69.          if(cnt > 2)
  70.          {
  71.             delete OBJ.once;
  72.             cnt = 0;
  73.          }
  74.       };
  75.       OBJ.onKeyUp = function()
  76.       {
  77.          delete this.once;
  78.       };
  79.       Key.addListener(OBJ);
  80.       this.watch(OBJ2,OBJ2.key,"key",funcForObj,0);
  81.    }
  82.    function watch(Obj, val, string, func, mid_val)
  83.    {
  84.       if(Obj.once_run == undefined)
  85.       {
  86.          Obj.once_run = 1;
  87.          if(Obj == undefined)
  88.          {
  89.             Obj = {};
  90.             Obj.val;
  91.          }
  92.          if(mid_val == undefined)
  93.          {
  94.             mid_val = 0;
  95.          }
  96.          var _loc4_ = function(prop, oldVal, newVal, mid_val)
  97.          {
  98.             func(prop,oldVal,newVal,mid_val);
  99.             if(newVal == "unwatch")
  100.             {
  101.                this.m_obj.unwatch();
  102.             }
  103.             return newVal;
  104.          };
  105.          Obj.watch(string,_loc4_,mid_val);
  106.       }
  107.    }
  108. }
  109.